﻿using BasicModuleOrm.Db_Context;
using Microsoft.EntityFrameworkCore;
using System.Configuration;

namespace BasicModuleOrm.ProductRespository.Respository
{
    public class ReposotoryOptions
    {
        public IServiceCollection services { get; set; }

        /// <summary>
        /// 选择
        /// </summary>
        public void UseEfCore()
        {
            //1、配置EfCoreContext
            services.AddDbContext<EfCoreContext>(options =>
            {
                // 2、配置MySQL
                options.UseMySql("server=192.168.60.129;port=3306;database=AspNetCore_ORMs;uid=root;pwd=123456",
                     new MySqlServerVersion(new Version(5, 7, 29)));
            });

            // 2、注册EfCoreRespository
            services.AddScoped(typeof(IRespository<>), typeof(EfCoreRespository<>));
        }

        /// <summary>
        /// 选择
        /// </summary>
        public void UseDapper()
        {
            // 2、配置DapperContext
            services.AddSingleton<DapperContext>();

            // 2、注册SqlSugarRespository
            services.AddScoped(typeof(IRespository<>), typeof(DapperRespository<>));
        }

        /// <summary>
        /// 选择
        /// </summary>

        public void UseSqlSugar()
        {
            // 3、配置SqlSugarContext
            services.AddSingleton(new SqlSugarContext());

            // 2、注册SqlSugarRespository
            services.AddScoped(typeof(IRespository<>), typeof(SqlSugarRespository<>));
        }
    }
}
